package com.yzc.controller;


import com.yzc.model.entity.system.RoleBean;
import com.yzc.model.entity.system.roleMenu;
import com.yzc.result.Result;
import com.yzc.service.RoleService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/role")
public class RoleController {

    final RoleService roleService;
    private static final Marker LOG_MARKER = MarkerFactory.getMarker("LOG");
    /**
     * 获取用户数据
     *
     * @return
     */

    @GetMapping("/loadRoleList")
    public Result<List<RoleBean>> loadRoleList() {
        log.info(LOG_MARKER, "查询角色列表");
        return Result.success(roleService.loadRoleList());
    }

    /**
     * 修改用户数据
     *
     * @return
     */
    @PutMapping("/update")
    public Result updateInfo(@RequestBody RoleBean roleBean) {
        log.info(LOG_MARKER, "修改角色信息");
        return Result.success(roleService.saveOrUpdate(roleBean));
    }

    /**
     * 更新用户数据
     *
     * @return
     */
    @PutMapping("/save")
    public Result save(@RequestBody RoleBean roleBean) {
        log.info(LOG_MARKER, "新增角色信息");
        return Result.success(roleService.saveOrUpdate(roleBean));
    }

    /**
     * 删除用户数据
     *
     * @return
     */
    @DeleteMapping("/delete")
    public Result deleteInfo(@RequestBody Long id) {
        log.info(LOG_MARKER, "删除角色信息");
        return Result.success(roleService.removeById(id));
    }


    /**
     * 根据id查询角色的菜单
     *
     * @return
     */
    @GetMapping("/loadRoleMenus")
    public Result<List<roleMenu>> loadRoleMenus(@RequestBody RoleBean roleBean) {
        log.info(LOG_MARKER, "查询角色对应的菜单信息");
        return Result.success(roleService.loadRoleMenus(roleBean));
    }

    @PutMapping("/saveAuthorizationRoleMenu")
    public Result saveAuthorizationRoleMenu(@RequestBody RoleBean roleBean) {
        log.info(LOG_MARKER, "保存角色授权菜单信息");
        return Result.success(roleService.saveOrUpdate(roleBean));
    }
}
